package org.hk.kg;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hk.kg.db.DBContext;
import org.hk.kg.db.DBContext.DBStatusHandler;
import org.hk.kg.ui.KGFrame;
import org.hk.kg.ui.KGStatusBar;
import org.hk.kg.ui.KGUiContext;
import org.hk.kg.ui.LoaderFrame;
import org.hk.kg.ui.LogonPanel;

public class KGMain {
	private static Log logger = LogFactory.getLog(KGMain.class);
	public static KGFrame body = new KGFrame();
	public static List<Runnable> tasks = new ArrayList<Runnable>();
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		LoaderFrame frame = new LoaderFrame();
		frame.prepareSplash(body);
		frame.startSplash();
		DBContext.instatnce.setHandler(new DBStatusHandler() {
			public void onCreateTableSuccess(String tableNames) {
				//statusBar.setStatusText("表" + tableNames + "创建成功");
			}
			
			public void onCreateTableFail(String tableNames, Throwable e) {
				//statusBar.setStatusText("表" + tableNames + "创建失败");
			}
			
			public void onCreateDBSuccess(String dbname) {
				//statusBar.setStatusText("数据库" + dbname + "创建成功");
			}
			
			public void onCreateDBFailure(String dbname) {
				//statusBar.setStatusText("数据库" + dbname + "创建失败");
			}
			
			public void onBeginCreateDB(String dbname) {
				//statusBar.setStatusText("开始创建数据库" + dbname);
			}
		});
		KGUiContext.instance.load();
		DBContext.instatnce.load();
		for(Runnable runnable:tasks)
		{
			runnable.run();
		}
		frame.stopSplash();
		
		//登陆页面
		LogonPanel logonPanel = new LogonPanel(body);
		
		final KGStatusBar statusBar = new KGStatusBar();
		KGUiContext.setStatus(statusBar);
		body.setStatusBar(statusBar);
		body.setLocationRelativeTo(null);
	}

}
